//
//  RootViewController.m
//  XMDLearn
//
//  Created by hao on 16/4/8.
//  Copyright © 2016年 hao. All rights reserved.
//

#import "RootViewController.h"
#import "MainViewController.h"
#import "VideoViewController.h"
#import "ChartViewController.h"
#import "UserViewController.h"


@interface RootViewController ()

@end

@implementation RootViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    MainViewController *main = [[MainViewController alloc] initWithNibName:@"MainViewController" bundle:nil];
    [self setupChildViewController:main title:@"首页" normalImage:@"shouye" selectedImage:@"shouye-select"];
    
    VideoViewController *video = [[VideoViewController alloc] initWithNibName:@"VideoViewController" bundle:nil];
    [self setupChildViewController:video title:@"视频" normalImage:@"shipin" selectedImage:@"shipin-select"];
    
    ChartViewController *chart = [[ChartViewController alloc] initWithNibName:@"ChartViewController" bundle:nil];
    [self setupChildViewController:chart title:@"社区" normalImage:@"shequ.png" selectedImage:@"shequ-select.png"];
    
    UserViewController *user = [[UserViewController alloc] initWithNibName:@"UserViewController" bundle:nil];
    [self setupChildViewController:user title:@"我的" normalImage:@"wode" selectedImage:@"wode-select"];

}

- (void)setupChildViewController:(UIViewController *)childVc title:(NSString *)title normalImage:(NSString *)normalImage selectedImage:(NSString *)selectedImage
{
    // 1.设置控制器的属性
    childVc.title = title;
    self.tabBar.tintColor = [UIColor colorWithRed:217.0/255.0 green:75.0/255.0 blue:64.0/255.0 alpha:1];
    // 设置图标
    childVc.tabBarItem.image = [[UIImage imageNamed:normalImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    // 2.包装一个导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childVc];
    [self addChildViewController:nav];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
